﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Security;

namespace Pub.Common
{
    public class SystemInfo
    {
        /// <summary>
        /// 获取服务器信息
        /// </summary>
        /// <returns></returns>
        public static string GetServerInfo()
        {
            string text = string.Empty;

            text += "<font>服务器OS：</font>" + Environment.OSVersion.ToString() + "<br />";
            text += "<font>CPU核心数：</font>" + Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS") + "个核心<br />";
            text += "<font>CPU类型：</font>" + Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER") + "<br />";
            text += "<font>IIS版本：</font>" + HttpContext.Current.Request.ServerVariables["SERVER_SOFTWARE"] + "<br />";
            text += "<font>服务器名：</font>" + HttpContext.Current.Server.MachineName + "<br />";
            text += "<font>服务器域名：</font>" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "<br />";
            text += "<font>虚拟服务绝对路径：</font>" + HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"] + "<br />";
            text += "<font>.Net版本：</font>" + ".NET CLR " + Environment.Version.ToString() + "<br />";
            text += "<font>脚本超时时间：</font>" + HttpContext.Current.Server.ScriptTimeout.ToString() + "毫秒<br />";
            text += "<font>开机运行时长：</font>" + ((Double)System.Environment.TickCount / 3600000).ToString("N2") + "小时<br />";
            text += "<font>Session总数：</font>" + HttpContext.Current.Session.Contents.Count.ToString() + "<br />";
            text += "<font>应用程序缓存总数：</font>" + HttpContext.Current.Cache.Count.ToString() + "<br />";
            text += "<font>本页执行时间：</font>" + HttpContext.Current.Server.ScriptTimeout.ToString() + "毫秒";

            return text;
        }
        /// <summary>
        /// 返回MD5加密字符串
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string Hash(string str)
        {
            string HashPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5");
            return HashPwd;
        }
    }
}
